<?php
    class Text extends Admin_Controller{
        function __construct(){
            parent::__construct();
            $this->load->model('Text_m');
        }
        function index(){
             $this->get_page_title();
        }
        function list_text($page_id){
            is_admin();
            $query1=$this->Text_m->get_page_title();
            $this->_data['all_page']=$query1;  
            $query=$this->Text_m->get_text_by_page_id($page_id);
            $this->_data['all_text']=$query;
            $this->_data['total']=$this->Text_m->count_text($page_id);
            $this->display_view('admin/list_text');
        }
        function edit_text($page_id,$id,$para){
            is_admin();
            $this->_data['page_title'] = "Edit text";
            $query=$this->Text_m->get_text_by_id($id);
            $this->_data['detail_text']=$query; 
            $this->_data['para']=$para;
            if ($this->input->post('submit')) {
               
                $formVal = array(
                array(
                'field' => 'description',
                'Label' => 'Description',
                'rules' => 'required'
                )
                );
                $this->form_validation->set_rules($formVal);
                if($this->form_validation->run()){
                    $data=array(
                    'para_text'=>$this->input->post('description'),
                    );
                    $this->Text_m->update_text($data,$id);
                    redirect('text/list_text/'.$page_id);
                }
                else
                {
                    $this->display_view('admin/edit_text'); 
                }
            }
            else{
                $this->display_view('admin/edit_text');
            }

        }
    }
?>
